import React from "react";
import { Form, Input, message, Button,  } from "antd";
import { useNavigate } from 'react-router-dom'
import axios from "axios";
const Index: React.FC = () => {
  const navigate = useNavigate()
  const onFinish = async (value: any) => {
    const resp = await axios.post("/api/login", value);
    const { code, data } = resp.data;
    console.log(resp.data);
    if (code === 200) {
      message.success("登录成功");
      localStorage.setItem('role', data.role)
      navigate('/sourcesviews')
    } else {
      message.error("登录失败");
    }
  };
  return (
    <div>
      <Form style={{ width: 500 }} labelCol={{ span: 3 }} onFinish={onFinish}>
        <Form.Item label="用户名" name="username">
          <Input></Input>
        </Form.Item>
        <Form.Item label="密码" name="password">
          <Input></Input>
        </Form.Item>
        <Form.Item wrapperCol={{ offset: 3 }}>
          <Button type="primary" block htmlType="submit">
            登录
          </Button>
        </Form.Item>
      </Form>
    </div>
  );
};

export default Index;
